var MAP_DICT = {};
layui.define(function (exports) {
    $.ajax({
        type: "POST",
        url: '/api/inter/ysDict/listAll',
        data: {},
        success: function (res) {
            if (res.code == 0) {
            	MAP_DICT = res.data
            } else {
                alert('加载字典选项失败');
            }
        }
    });
	var object = {
			c: {data:[]}, // 配置项
			f: function (c) { // 数据初始化
				var s = new Date().getTime(),t = this;
				
				if (!c.modalKey) {
					alert('未配置弹出框');
					return;
				}
				t.c = c;
				
				if(!c.type) {
					t.c.type = 'radio'; // 默认单选框
				} else {
					if (!t.c.uniqueKey) {
						alert('复选框必须指定唯一识别码KEY');
						return;
					}
				}
				
				t.c.id_modal_select_form = 'id_modal_select_form_' + (new Date().getTime()); // 生成表单ID
				t.c.id_modal_select_grid_left = 'id_modal_select_grid_left_' + (new Date().getTime()); // 生成表格ID
				t.c.id_modal_select_grid_right = 'id_modal_select_grid_right_' + (new Date().getTime()); // 生成表格ID
				
				// 处理默认条件
				t.c.conditionsDefault = c.conditionsDefault;
				if (!t.c.conditionsDefault) {
					t.c.conditionsDefault = [];
				}
				
				// 加载弹出框配置
				$.ajax({
					async: false, // 同步获取
					type: "POST",
					url: '/api/inter/ysModalSelector/modalConfig',
					data: {
						modalKey: t.c.modalKey,
						multySelected: (t.c.type == 'radio' ? 0 : 1)
					},
					success: function (data) {
						if (data.code == 0) {
							t.c.modalSelect = data.data;
							
							console.log(data.data);
							
							// 处理默认条件
							for (var i = 0; i < t.c.modalSelect.conditions.length; i++) {
								var condition = t.c.modalSelect.conditions[i];
								for (var j = 0; j < t.c.conditionsDefault.length; j++) {
									var conditionDefault = t.c.conditionsDefault[j];
									if (conditionDefault.code == condition.code) {
										t.c.modalSelect.conditions[i].value = conditionDefault.value;
									}
								}
							}
						} else {
							alert(data.msg);
						}
					}
				});
			},
			load:function () { // 加载表单
				var t = this;
				
				if(t.c.type == 'radio') {
					this.loadRadio();
				} else {
					this.loadCheckbox();
				}
				this.listenBtn();
			},
			loadRadio: function() {
				var t = this;
				var content = 
					`<div class="ysui-row" style="max-height: 100px; overflow: auto;">`
						+ `<div style="background-color: #ffffff; width: 100%;">`
							+ `<div style="background-color: #ffffff;">`
								+ `<form class="layui-form margin_0" id="` + t.c.id_modal_select_form + `" style="padding: 0.2rem;">`
									+ `<div class="layui-form-item margin_0">`
										+ t.loadModalInput(t.c.modalSelect.conditions)
										+ t.loadModalSelectFormBtn()
									+ `</div>`
								+ `</form>`
							+ `</div>`
						+ `</div>`
					+ `</div>`
					+ `<div class="ysui-col" style="width: 100%;">`
						+ `<table class="layui-hide" id="` + t.c.id_modal_select_grid_left + `" lay-filter="` + t.c.id_modal_select_grid_left + `"></table>`
						+ `<script type="text/html" id="templet_index_no">`
							+ `{{d.LAY_TABLE_INDEX+1}}`
						+ `</script>`
					+ `</div>`
					+ t.loadScriptTPL();
				
				var w=($(window).width()*0.8);
				var h=($(window).height() - 50);
				layer.open({
					type: 1,
					area: [w + 'px', h + 'px'],
					fix: false,
					//不固定
					maxmin: true,
					shade: 0.6,
					title: '弹出选择框',
					content: content,
					btn: ['确定', '关闭'],
					//点击弹层外区域关闭
					shadeClose: true,
            		yes: function (index) {// 点击“确定”，执行的回调函数
            			var checkStatus = layui.table.checkStatus(t.c.id_modal_select_grid_left);
            			var dataSelected = checkStatus.data;
            			if (dataSelected.length == 0) {
            				alert("请选择一条数据");
							return;
						}
						t.c.parentObj.matchValuesAfterModalSelectRadio(t.c.colCode, checkStatus.data[0], t.c.extraData);
						layer.close(index);
            		},
					btn2: function(index, layero){
						layer.close(index);
					},
					success: function(layero, index) {
						t.listenModalSelectBtn(); // 添加弹出层按钮监听
						layui
						.use(['form', 'element', 'table', 'util', 'laydate'], function(){
							var element = layui.element;
							var table = layui.table;
							var form = layui.form;
							var util = layui.util;
							var $ = layui.jquery;
							var laydate = layui.laydate;
							
							// 创建渲染实例
							table.render({
								elem: '#' + t.c.id_modal_select_grid_left
								,url:t.c.modalSelect.pathGridRequest
								,defaultToolbar: [{
										title: '刷新页面'
										,layEvent: 'LAYTABLE_REFRESH'
										,icon: 'layui-icon-refresh'
									}]
								,height: 'full-240' // 最大高度减去其他容器已占有的高度差
								,limit : 20
								,limits : [20,50,500,9999]
								,where: {'conditions': JSON.stringify(t.getCondsOfModalSelect())}
								,cellMinWidth: 150
								,totalRow: false // 开启合计行
								,page: true
								,request: {
									pageName: 'page',
									limitName: 'size'
								}
								,even: false // 开启隔行背景
								,cols: [t.c.modalSelect.colGrids]
								,done: function(){
								}
								,error: function(res, msg){
									console.log(res, msg)
								}
							});
							
							// 行双击事件
							table.on('rowDouble(' + t.c.id_modal_select_grid_left + ')', function(obj){
								t.c.parentObj.matchValuesAfterModalSelectRadio(t.c.colCode, obj.data, t.c.extraData);
								layer.close(index);
							});
						});
					}
				});
			},
			loadCheckbox: function() {
				var t = this;
				var content = 
					`<div class="ysui-row" style="max-height: 100px; overflow: auto;">`
						+ `<div style="background-color: #ffffff; width: 100%;">`
							+ `<div style="background-color: #ffffff;">`
								+ `<form class="layui-form margin_0" id="` + t.c.id_modal_select_form + `" style="padding: 0.2rem;">`
									+ `<div class="layui-form-item margin_0">`
										+ t.loadModalInput(t.c.modalSelect.conditions)
										+ t.loadModalSelectFormBtn()
									+ `</div>`
								+ `</form>`
							+ `</div>`
						+ `</div>`
					+ `</div>`
					+ `<div class="ysui-col" style="width: 45%; float: left;">`
						+ `<table class="layui-hide" id="` + t.c.id_modal_select_grid_left + `" lay-filter="` + t.c.id_modal_select_grid_left + `"></table>`
						+ `<script type="text/html" id="templet_index_no">`
							+ `{{d.LAY_TABLE_INDEX+1}}`
						+ `</script>`
					+ `</div>`
					+ `<div class="layui-btn-container" style="width: 50px;text-align: center;margin-top:10%; float: left;">`
						+ `<div class="layui-btn layui-btn-disabled" data-filter="add-to-right" style="padding:0 10px;margin-right: 0;">`
							+ `<p class="layui-icon layui-icon-next" style="font-size:14px;margin:0;color:#C9C9C9"></p>`
						+ `</div>`
						+ `<div class="layui-btn layui-btn-disabled" data-filter="remove-from-right" style="padding:0 10px;margin-right: 0;">`
							+ `<p class="layui-icon layui-icon-prev" style="font-size:14px;margin:0;color:#C9C9C9"></p>`
						+ `</div>`
					+ `</div>`
					+ `<div class="ysui-col" style="width: 45%; style="float: right;">`
						+ `<table class="layui-hide" id="` + t.c.id_modal_select_grid_right + `" lay-filter="` + t.c.id_modal_select_grid_right + `"></table>`
					+ `</div>`;
					
				var w=($(window).width()*0.8);
				var h=($(window).height() - 50);
				layer.open({
					type: 1,
					area: [w + 'px', h + 'px'],
					fix: false,
					//不固定
					maxmin: true,
					shade: 0.6,
					title: '弹出选择框',
					content: content,
					btn: ['确定', '取消'],
					//点击弹层外区域关闭
					shadeClose: true,
					success: function(layero, index) {
						t.listenModalSelectBtn(); // 添加弹出层按钮监听
						
						t.loadTableLeft();
						t.loadTableRight();
					},
					yes: function(index, layero){
						// 验证指定字段唯一
						if(t.c.sameCode && t.c.selectedData.length > 1) {
							var sameValue = t.c.selectedData[0][t.c.sameCode];
							for (var i = 1; i < t.c.selectedData.length; i++) {
								var sameValueOfRow = t.c.selectedData[i][t.c.sameCode];
								if(sameValue != sameValueOfRow) {
									
									for (var j = 0; j < t.c.modalSelect.colGrids.length; j++) {
										var colGrid = t.c.modalSelect.colGrids[j];
										if (t.c.sameCode == colGrid.field) {
											layer.msg(colGrid.title + '必须唯一');
											return;
										}
									}
								}
							}
						}
						
						t.c.parentObj.matchValuesAfterModalSelectCheckbox(t.c.selectedData, t.c.extraData);
						layer.close(index);
					},
					btn2: function(index, layero){
						layer.close(index);
					}
				});
			},
			loadTableLeft() {
				var t = this;
				// 创建渲染实例
				layui.table.render({
					elem: '#' + t.c.id_modal_select_grid_left
					,url:t.c.modalSelect.pathGridRequest
					,defaultToolbar: [{
							title: '刷新页面'
							,layEvent: 'LAYTABLE_REFRESH'
							,icon: 'layui-icon-refresh'
						}]
					,height: 'full-240' // 最大高度减去其他容器已占有的高度差
					,limit : 20
					,limits : [20,50,500,9999]
					,where: {'conditions': JSON.stringify(t.getCondsOfModalSelect())}
					,cellMinWidth: 150
					,totalRow: false // 开启合计行
					,page: true
					,request: {
						pageName: 'page',
						limitName: 'size'
					}
					,even: false // 开启隔行背景
					,cols: [t.c.modalSelect.colGrids]
					,done: function(){
					}
					,error: function(res, msg){
						console.log(res, msg)
					}
				});
				
				// 行双击事件
				layui.table.on('rowDouble(' + t.c.id_modal_select_grid_left + ')', function(obj){
					console.log(11111111);
					layer.close(index);
				});
			},
			loadTableRight() {
				var t = this;
				// 创建渲染实例
				layui.table.render({
					elem: '#' + t.c.id_modal_select_grid_right
					,data: t.c.selectedData
					,height: 'full-240' // 最大高度减去其他容器已占有的高度差
					,limit : 9999
					,cellMinWidth: 150
					,even: false // 开启隔行背景
					,cols: [t.c.modalSelect.colGrids]
					,done: function(){
						// 清除选中状态
						 $('div.laytable-cell-checkbox').find('div.layui-form-checked').click();
					}
					,error: function(res, msg){
						console.log(res, msg)
					}
				});
			},
			loadScriptTPL: function() {
				var t = this;

				var h = ``;
				for (var i = 0; i < t.c.modalSelect.colGrids.length; i++) {
					var colGrid = t.c.modalSelect.colGrids[i];
					
					var baseDictKey = colGrid.baseDictKey;
					if(baseDictKey) {
						h += ``
							+ `<script type="text/html" id="templet_script_tpl_for_modal_` + colGrid.field + `">`
							+ `{{# layui.each(MAP_DICT['` + baseDictKey + `'], function(index, item){     }}`
								+ `{{#  if(item.value == d.` + colGrid.field + `){ }}`
								+ `<span>{{item.name}}</span>`
								+ `{{#  } }}`
							+ `{{# });}}`
							+ `</script>`;
					}
				}
				return h;
			},
			listenBtn:function () { // 添加监听
				
				// layui表单渲染，使控件生效
				layui.form.render();
				
				var t = this;
				
				// 复选框类型时添加左右按钮监听
				if(t.c.type == 'checkbox') {
					// 监听“>>”按钮
					$('div[data-filter="add-to-right"]').on('click',function (e) {
						var checkStatus = layui.table.checkStatus(t.c.id_modal_select_grid_left)
						t.addRows(checkStatus.data);
					});
					
					// 监听“<<”按钮
					$('div[data-filter="remove-from-right"]').on('click',function (e) {
						var checkStatus = layui.table.checkStatus(t.c.id_modal_select_grid_right)
						t.removeRows(checkStatus.data);
					});
				}
				
				// 初始化开关
				layui.form.on('switch(switch_on_form)', function(data){
					console.log(this);
					var nameOfInput = $(this).attr('data-name-for-input');
					
					//更改选中和未选中时，传到后台的值，此时选中传1，未选中传0。
					domForm.find('input[name="' + nameOfInput + '"]').val(this.checked ? 1 : 0);
				});
				
				// 行双击事件-左表
				layui.table.on('rowDouble(' + t.c.id_modal_select_grid_left + ')', function(obj){
					console.log(2222222222222);
					layer.close(index);
				});
				
				// 复选框类型时添加双击
				if(t.c.type == 'checkbox') {
					// 行双击事件-左表
					layui.table.on('rowDouble(' + t.c.id_modal_select_grid_left + ')', function(obj){
						var datas = [];
						datas.push(obj.data);
						t.addRows(datas);
					});
					// 行双击事件-右表
					layui.table.on('rowDouble(' + t.c.id_modal_select_grid_right + ')', function(obj){
						var datas = [];
						datas.push(obj.data);
						t.removeRows(datas);
					});
				}
			},
			loadModalInput: function(conditions) {
				var h = ``;
				for (var i = 0; i < conditions.length; i++) {
					var condition = conditions[i];
					if(condition.type == 't_text') {
						h += this.loadModalSelectText(condition, i);
					} else if(condition.type == 't_dropdown') {
						h += this.loadModalSelectDropdown(condition, i);
					} else if(condition.type == 't_checkbox') {
						h += this.loadModalSelectCheckbox(condition, i);
					} else if(condition.type == 't_radio') {
						h += this.loadModalSelectRadio(condition, i);
					} else if(condition.type == 't_year') {
						h += this.loadModalSelectYear(condition, i);
					} else if(condition.type == 't_month') {
						h += this.loadModalSelectMonth(condition, i);
					} else if(condition.type == 't_date') {
						h += this.loadModalSelectDate(condition, i);
					} else if(condition.type == 't_datetime') {
						h += this.loadModalSelectDatetime(condition, i);
					}
				}
				return h;
			},
			loadModalSelectText:function (condition, index) { // 加载文本输入框
				var str = ``
					+ `<div class="layui-inline layui-col-xs3 layui-col-md3 margin_0" data-index="` + index + `">`
						+ `<label class="layui-form-label margin_0 padding_4_0 width_70 text_overflow_ellipsis">` + condition.name + `:</label>`
						+ `<div class="layui-input-block height_30 line_height_30 margin_l_70">`
							+ `<input data-index="` + index + `" data-filter="ysui_modal_search_form_item" data-code="` + condition.code + `" type="text" autocomplete="off" placeholder="` + condition.placeHolder + `" cond-range-type="` + condition.rangeType + `" value="` + (condition.value ? condition.value : ``) + `" class="layui-input height_30" style="border: solid 0.1px; border-color: #B5B5B5; width:90%;">`
						+ `</div>`
					+ `</div>`;
				return str;
			},
			loadModalSelectDropdown:function (condition, index) { // 加载下拉框(普通)
				var h = ``;
				h += `<div class="layui-inline layui-col-xs3 layui-col-md3 margin_0" data-index="` + index + `">`;
					h += `<label class="layui-form-label margin_0 padding_4_0 width_70 text_overflow_ellipsis">` + condition.name + `:</label>`;
					h += `<div class="layui-input-block height_30 line_height_30 margin_l_70">`
						h += `<select data-index="` + index + `" data-filter="ysui_modal_search_form_item" data-code="` + condition.code + `" cond-range-type="` + condition.rangeType + `">`;
						for (var i = 0; i < condition.optionArr.length; i++) {
							var option = condition.optionArr[i];
							h += `<option value="` + option.value + `">` + option.name + `</option>`;
						}
						h += `</select>`;
					h += `</div>`;
				h += `</div>`;
				return h;
			},
			loadModalSelectCheckbox:function (objInput) { // 加载转换框
				var str = ``
					+ `<div class="layui-inline layui-col-xs4 margin_r_0">`
						+ `<label class="layui-form-label">` + (objInput.required == 1 ? `<font class="f_red">*</font>` : ``) + objInput.name + `：</label>`
						+ `<div class="layui-input-block">`
							+ `<input type="hidden" name="` + objInput.code + `" value="` + (objInput.value ? 1 : 0) + `">`
							+ `<input type="checkbox" data-name-for-input="` + objInput.code + `" lay-skin="switch" lay-filter="switch_on_form" lay-text="是|否" ` + (objInput.value != null && objInput.value == 1 ? `checked` : ``) + `>`
						+ `</div>`
					+ `</div>`;
				return str;
			},
			loadModalSelectRadio:function (objInput) { // 加载单选框
				var t = this;
				var str = ``
					+ `<div class="layui-inline layui-col-xs4 margin_r_0">`
						+ `<label class="layui-form-label">` + (objInput.required == 1 ? `<font class="f_red">*</font>` : ``) + objInput.name + `：</label>`
						+ `<div class="layui-input-block">`;
				
				// 字典数据
				if(objInput.dictKey) {
					var listOption = t.c.dict[objInput.dictKey];
					for(var i=0;i<listOption.length;i++){
						var option = listOption[i];
						str += `<input type="radio" name="` + objInput.code + `" value="` + option.value + `" title="` + option.name + `" ` + (objInput.value != null && objInput.value == option.value ? `checked` : ``) + `>`;
					}
				}
				str += 	`</div>`;
				str += `</div>`;
				return str;
			},
			loadModalSelectYear:function (objInput) { // 加载年份（YYYY）
				var str = ``
					+ `<div class="layui-inline layui-col-xs4 margin_r_0">`
						+ `<label class="layui-form-label">` + (objInput.required == 1 ? `<font class="f_red">*</font>` : ``) + objInput.name + `：</label>`
						+ `<div class="layui-input-block">`
							+ `<input readonly type="text" name="` + objInput.code + `" value="` + (objInput.value ? objInput.value : ``) + `" class="layui-input height_24 buttontext cannot_edit" ` + (objInput.required == 1 ? `lay-verify="required"` : ``) + `>`
							+ `<i style="position: absolute; right: 2px; top:0px; height: 30px; line-height: 30px; width: 25px;" class="layui-icon layui-icon-more" lay-filter="buttontextModel" modalKey="` + objInput.modalKey + `" colCode="` + objInput.code + `"></i>`
						+ `</div>`
					+ `</div>`;
				return str;
			},
			loadModalSelectDate:function (objInput) { // 加载日期（YYYY-MM-DD）
				var str = ``
					+ `<div class="layui-inline layui-col-xs4 margin_r_0">`
						+ `<label class="layui-form-label">` + (objInput.required == 1 ? `<font class="f_red">*</font>` : ``) + objInput.name + `：</label>`
						+ `<div class="layui-input-block">`
							+ `<input readonly type="text" name="` + objInput.code + `" value="` + (objInput.value ? objInput.value : ``) + `" class="layui-input height_24 buttontext cannot_edit" ` + (objInput.required == 1 ? `lay-verify="required"` : ``) + `>`
							+ `<i style="position: absolute; right: 2px; top:0px; height: 30px; line-height: 30px; width: 25px;" class="layui-icon layui-icon-more" lay-filter="buttontextModel" modalKey="` + objInput.modalKey + `" colCode="` + objInput.code + `"></i>`
						+ `</div>`
					+ `</div>`;
				return str;
			},
			loadModalSelectDatetime:function (objInput) { // 加载日期（YYYY-MM-DD hh:mm:ss）
				var str = ``
					+ `<div class="layui-inline layui-col-xs4 margin_r_0">`
						+ `<label class="layui-form-label">` + (objInput.required == 1 ? `<font class="f_red">*</font>` : ``) + objInput.name + `：</label>`
						+ `<div class="layui-input-block">`
							+ `<input readonly type="text" name="` + objInput.code + `" value="` + (objInput.value ? objInput.value : ``) + `" class="layui-input height_24 buttontext cannot_edit" ` + (objInput.required == 1 ? `lay-verify="required"` : ``) + `>`
							+ `<i style="position: absolute; right: 2px; top:0px; height: 30px; line-height: 30px; width: 25px;" class="layui-icon layui-icon-more" lay-filter="buttontextModel" modalKey="` + objInput.modalKey + `" colCode="` + objInput.code + `"></i>`
						+ `</div>`
					+ `</div>`;
				return str;
			},
			loadModalSelectFormBtn:function () { // 加载按钮
				var h =
					`<div class="layui-inline layui-col-xs3 layui-col-md3 margin_0">`
						+ `<a data-filter="filter_form_search" class="layui-btn layui-btn-normal layui-btn-sm search_btn"><i class="layui-icon layui-icon-search"></i> 查询</a>`
						+ `<button data-filter="filter_form_clear" type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-filter="filter_form_search_clear"><i class="layui-icon layui-icon-close"></i> 清空</button>`
					+ `</div>`;
				return h;
			},
			listenModalSelectBtn:function () { // 添加弹出层监听
				
				// layui表单渲染，使控件生效
				// layui.form.render();
				
				var t = this;
				// 监听“查询”按钮
				$('#' + t.c.id_modal_select_form).find('a[data-filter="filter_form_search"]').on('click',function (e) {
					layui.table.reload(t.c.id_modal_select_grid_left, {
						page: {curr: 1},
						where: {'conditions': JSON.stringify(t.getCondsOfModalSelect())}
					})
				});
				
				// 单选框时添加监听
				if (t.c.type == 'radio') {
		            //点击table行选中单选框
		            $(document).on('click', '.layui-table-body table.layui-table tbody tr', function () {
		                var obj = event ? event.target : event.srcElement;
		                var tag = obj.tagName;
		                var radio = $(this).find('td div.laytable-cell-radio div.layui-form-radio I');
		                if (radio.length != 0) {
		                    if (tag == 'DIV') {
		                    	radio.click();
		                    }
		                }
		            });
		            //点击单选框阻止冒泡
		            $(document).on('click', '.layui-form-radio', function (e) {
		                e.stopPropagation();
		            });
				}
				
				// 多选框时添加监听
				if (t.c.type == 'checkbox') {

		            //点击table行选中复选框
		            $(document).on('click', '.layui-table-body table.layui-table tbody tr', function () {
		                var obj = event ? event.target : event.srcElement;
		                var tag = obj.tagName;
		                var checkbox = $(this).find('td div.laytable-cell-checkbox div.layui-form-checkbox I');
		                if (checkbox.length != 0) {
		                    if (tag == 'DIV') {
		                        checkbox.click();
		                    }
		                }
		            });
		            //点击复选框阻止冒泡
		            $(document).on('click', '.layui-form-checkbox', function (e) {
		                e.stopPropagation();
		                var data = [], data2 = [];
		                var checkStatus = layui.table.checkStatus(t.c.id_modal_select_grid_left);
		                data = checkStatus.data;
		                if (data.length > 0) {
		                    $('div[data-filter="add-to-right"]').removeClass('layui-btn-disabled');
		                    $('div[data-filter="add-to-right"]').children().css('color', '#fff');
		                } else {
		                    $('div[data-filter="add-to-right"]').addClass('layui-btn-disabled');
		                    $('div[data-filter="add-to-right"]').children().css('color', '#C9C9C9');
		                }
		                var checkStatus2 = layui.table.checkStatus(t.c.id_modal_select_grid_right);
		                data2 = checkStatus2.data;
		                if (data2.length > 0) {
		                    $('div[data-filter="remove-from-right"]').removeClass('layui-btn-disabled');
		                    $('div[data-filter="remove-from-right"]').children().css('color', '#fff');
		                } else {
		                    $('div[data-filter="remove-from-right"]').addClass('layui-btn-disabled');
		                    $('div[data-filter="remove-from-right"]').children().css('color', '#C9C9C9');
		                }
		            });
				}
			},
			getCondsOfModalSelect:function () {
				var t = this;
				var conditionsRes = [];
				$('#' + t.c.id_modal_select_form).find('[data-filter="ysui_modal_search_form_item"]').each(function(index, domEle){
					
					var v = $(this).val();
					if(v) {
						var i = $(this).attr('data-index');
						var condition = t.c.modalSelect.conditions[i];
						conditionsRes.push({'rangeType':condition.rangeType, 'value': v, 'field':condition.code});
					}
				});
				return conditionsRes;
			},
			addRows: function(rows) {
				var t = this;
				for (var i = 0; i < rows.length; i++) {
					var row = rows[i];
					
					var isAbleAdd = false;
					for (var j = 0; j < t.c.selectedData.length; j++) {
						var selectedData = t.c.selectedData[j];
						if (selectedData[t.c.uniqueKey] == row[t.c.uniqueKey]) {
							isAbleAdd = true;
						}
					}
					
					if (isAbleAdd == false) {
						t.c.selectedData.push(row);
					}
				}
				t.loadTableRight();
			},
			removeRows: function(rows) {
				var t = this;
				// 从数组中移除
				for (var i = 0; i < rows.length; i++) {
					var row = rows[i];
					for (var j = 0; j < t.c.selectedData.length; j++) {
						var selectedData = t.c.selectedData[j];
						if (selectedData[t.c.uniqueKey] == row[t.c.uniqueKey]) {
				        	t.c.selectedData.splice(j, 1);
						}
					}
				}
				t.loadTableRight();
			},
			init:function (c) {
				this.f(c);
				this.load();
				return object;
			}
		};
	exports('YsModal', object);
});